<%@page import="java.util.List"%>
<%@page import="fun.wlfj.vo.Product"%>
<%@page import="fun.wlfj.vo.User"%>
<%@page import="fun.wlfj.factory.CashSystemFactory"%>
<%@page import="fun.wlfj.vo.PayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<% String which = "处方划价"; %>
<%@ include file="/header.jsp"%>
<!-- CONTENT -->
<section id="content">
	<div class="page dashboard-page">
		<!-- bradcome -->
		<!-- row -->
		<div class="row">
			<div class="col-md-6">
				<section class="boxs">
					<div class="boxs-header">
						<h3 class="custom-font hb-green">
							<strong>划价</strong>窗口
						</h3>
					</div>
					<div class="boxs-body">
					<%
					if(session.getAttribute("message") != null){
						%>
						<div class="alert alert-success"> <%=session.getAttribute("message") %> </div>
						<%
						session.setAttribute("message", null);
					}
					%>
					
					<%
					Integer PayListID = (Integer)session.getAttribute("NewPayListID");
					User user = null;
					if(PayListID != null){
						user = (User)session.getAttribute("User");
						if(user == null){
							response.sendRedirect("clearEnv");
							return;
						}
					%>
					<form class="form-horizontal" role="form" action="addProduct" method="POST">
							<input type="hidden" name="PayListID" value="<%=PayListID%>">
							<div class="form-group">
								<label for="showPayListID" class="col-sm-2 control-label">划价单号</label>
								<div class="col-sm-10">
									<label id="showPayListID" class="control-label"><%=PayListID %></label>
								</div>
							</div>
							<div class="form-group">
								<label for="showSum" class="col-sm-2 control-label">小计金额</label>
								<div class="col-sm-10">
									<label id="showSum" class="control-label"><%=CashSystemFactory.getPayListDao(user).getPayListByID(user.getUserID(), PayListID).getPayCash() %>¥</label>
								</div>
							</div>
							<div class="form-group">
								<label for="inputShortName" class="col-sm-2 control-label">项目缩写</label>
								<div class="col-sm-10">
									<input type="text" name="ProductShortName" class="form-control" id="inputShortName"
										placeholder="请输入项目简称,请注意库存.">
								</div>
							</div>
							<div class="form-group">
								<label for="inputCount" class="col-sm-2 control-label">购买数量</label>
								<div class="col-sm-10">
									<input type="number" name="Count" class="form-control" id="inputCount"
										placeholder="请输入购买数量">
								</div>
							</div>
							<button type="submit" class="btn btn-raised btn-primary">添加</button>
							<a href="clearEnv" class="btn btn-raised btn-primary">结束添加</a>
						</form>
					 <%}else{ %>
						<form class="form-horizontal" role="form" action="createPay" method="POST">
							<div class="form-group">
								<label for="inputUserName" class="col-sm-2 control-label">患者姓名</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="inputUserName"
										placeholder="请输入患者姓名" name="UserName">
								</div>
							</div>
							<button type="submit" class="btn btn-raised btn-primary">开始划价</button>
							<button type="reset" class="btn btn-raised btn-primary">重置</button>
						</form>
						<%} %>
					</div>
				</section>
			</div>
			<div class="col-md-6">
				<section class="boxs">
					<div class="boxs-header">
						<h3 class="custom-font hb-cyan">
							<strong>查询</strong>窗口
						</h3>
					</div>
					<div class="boxs-body">
						<form class="form-horizontal" role="form" action="queryProduct" method="POST">
							<%
							Product product = (Product)request.getAttribute("ProductInfo");
							if(product != null){
								%>
							<div class="form-group">
								<label for="showPayListID" class="col-sm-2 control-label">项目名称</label>
								<div class="col-sm-10">
									<label id="showPayListID" class="control-label"><%=product.getProductName() %></label>
								</div>
							</div>
							<div class="form-group">
								<label for="showSum" class="col-sm-2 control-label">单价</label>
								<div class="col-sm-10">
									<label id="showSum" class="control-label"><%=product.getProductPrice() %>¥</label>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">库存</label>
								<div class="col-sm-10">
									<label class="control-label"><%=product.getProductNums() %></label>
								</div>
							</div>
								<%
								
							}
							
							%>
							<div class="form-group">
								<label for="inputShortName" class="col-sm-2 control-label">项目缩写</label>
								<div class="col-sm-10">
									<input type="text" class="form-control" id="inputShortName" name="ProductShortName"
										placeholder="请输入项目简称">
								</div>
							</div>
							<button type="submit" class="btn btn-raised btn-primary">查询</button>
							<button type="reset" class="btn btn-raised btn-primary">重置</button>
						</form>
					</div>
				</section>
			</div>
		</div>
		<%if(PayListID != null && user != null && PayListID != null) {
		//我们要查询当前项目已有购买清单
		PayList pl = CashSystemFactory.getPayListDao(user).getPayListByID(user.getUserID(), PayListID);
		List<Product> list = pl.getProducts();
		%>
		<div class="row">
			<div class="col-md-12">
				<section class="boxs">
					<div class="boxs-header">
						<h3 class="custom-font hb-blue">
							<strong>当前</strong>已有项目
						</h3>
					</div>
					<div class="boxs-body">

						<table class="table table-hover">
							<thead>
								<tr>
									<th>#</th>
									<th>付费项目名称</th>
									<th>数量</th>
									<th>单价</th>
									<th>总价</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
							<%
							int cnt = 1;
							for(Product p : list){
							%>
								<tr>
									<td><%=cnt ++ %></td>
									<td><%=p.getProductName() %></td>
									<td><%=p.getCount() %></td>
									<td><%=p.getProductPrice() %>¥</td>
									<td><%=p.getCount() * p.getProductPrice() %>¥</td>
									<td><a href="deleteProduct?PayListID=<%=PayListID %>&ProductID=<%=p.getProductID() %>"
										class="btn btn-raised btn-danger">删除</a></td>
								</tr>
								<%} %>
							</tbody>
						</table>
					</div>
				</section>
			</div>
		</div>
		<%} %>
	</div>
</section>
<%@ include file="/footer.jsp"%>